<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<%@ include file="./../../header_inc.jsp"%>
<script type="text/javascript">
	//所有的子窗体都需要有一个save函数，当点击弹出窗体的保存按钮时所进行的操作

	function btnSave_click() {
		var fun_ret;
		var file = $('#uploadFile')[0];
		var imagSize =  document.getElementById("uploadFile").files[0];
		var status =  document.getElementById("status").value;
		if(imagSize != null && imagSize != "" && !isNull( imagSize )){
			imagSize = imagSize.size;
		}
		name = file.value;
		var pic = /.+(.JPEG|.jpeg|.JPG|.jpg|.GIF|.gif|.BMP|.bmp|.PNG|.png)$/;
		var end = name.substr(name.lastIndexOf("."));
		if (status == "" || status == null || isNull(status)){
			$.messager.alert("错误提示", "状态不能为空！");
			return false;
		}else{
			if (name != "" && name != null && end !=".jpg" && end !=".JPEG" && end !=".jpeg" &&end !=".JPG" && end !=".PNG" && end !=".png" ) {
				$.messager.alert("提示", " 您选择的不是图片文件，请重新选择！");
				return false;
			}else{
				if(imagSize > 204800){
						$.messager.alert("错误提示", "图片需要限制在200kb以内！");
				        return false;
				}
			}
			var formData = new FormData($('#formModule')[0]);
			
			$.ajax(
					{
						url : '${saveUrl}', //server script to process data
						type : 'POST',
						data : formData,
						async: false,
						cache : false,
						contentType : false,
						processData : false,
						dataType:'json',//请求的数据类型
						xhr : function() { // custom xhr
							myXhr = $.ajaxSettings.xhr();
							if (myXhr.upload) { // if upload property exists
								myXhr.upload.addEventListener('progress',
										progressHandlingFunction, false); // progressbar
							}
							return myXhr;

						},
						//Ajax events
						success : function(data) {
				               if(data.success == 0 )
				               {
				            	   fun_ret = true;
				               }
				               else
				               {
				            	   top.Ext.Msg.alert("返回提示",data.msg);
				               }
				           },
						error : errorHandler = function(data) {
							$.messager.alert("错误提示", data.msg);
							return false;
						}
					});	
		}
		
		
		return fun_ret;
	}
	function progressHandlingFunction(e) {
		if (e.lengthComputable) {
			$('progress').attr({
				value : e.loaded,
				max : e.total
			});
		}
	}

	
</script>
</head>
<body>
	<div style="padding: 1px" align="center">
	
		<form id="formModule" method="post" >
			<table border="0">
				 <tr height="0">
					<td><c:if test="${!empty model.depId }"><input type="hidden" value="${model.depId }" name="depId"></input></c:if></td>
				</tr> 
				<tr height="30">
					<td>部门名称：</td>
					<td><input id="depName" maxlength="10" placeholder="请输入2-4位部门名称"
						class="easyui-validatebox textbox" type="text"
						name="depName" data-options="required:true"
						style="width: 180px;height: 25px;text-align:center" value="${model.depName }"></input></td>
				</tr>
				<tr>
					<td>状态：</td>
					<td><select id="status" name="status">
							<option value="9" <c:if test="${model.status==9 }">selected</c:if>>正常</option>
							<option value="0" <c:if test="${model.status==0 }">selected</c:if>>禁用</option>
					</select></td>
				</tr>
				<tr>
                    <td height="28">部门图标：</td>
                    <td><input type="file" class="easyui-linkbutton"
						data-options="toggle:true,group:'g2',plain:true"
						accept="image/*" id="uploadFile"
						name="uploadFile" style="width: 200px;" value="${model.depIcon }"/></td>
                </tr>
				
			</table>
		</form>
	</div>
</body>
</html>
